<?php

$term = filter_input(INPUT_GET, 'term', FILTER_SANITIZE_STRING);
//$term = isset($_GET['term']) ? trim($_GET['term']) : '';
if (!empty($term)) {

    include '../includes/db_connect.inc.php';

    $safe_term = mysql_real_escape_string($term);

    $sql_query = "SELECT * FROM kneipen 
                    WHERE
                        Name LIKE '%$safe_term%'
                    OR
                        Art LIKE '%$safe_term%'
                    OR
                        Kommentar LIKE '%$safe_term%'
                    LIMIT 0,10";

    $result = $db_con->query($sql_query);
    $results = array();
    while ($row = $result->fetch_assoc()) {
        $results[] = $row['Name'];
    }
    
    echo json_encode($results);
}
